﻿using System;

namespace Comsenz.Base
{
    /// <summary>
    /// 模仿PHP的一些方法
    /// </summary>
    /// <author>Chiron</author>
    public static class PhpFunc
    {
        public static string Microtime()
        {
            //得到1970年的时间戳
            DateTime timeStamp = new DateTime(1970, 1, 1);
            //注意这里有时区问题，用now就要减掉8个小时
            long sec = (DateTime.UtcNow.Ticks - timeStamp.Ticks) / 10000000;
            int msec = DateTime.UtcNow.Millisecond;
            string strMsec = "0." + msec.ToString().PadRight(8, '0');
            string strRet = strMsec + " " + sec.ToString();
            return strRet;
        }

        public static int Time()
        {
            return (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
        }
    }
}
